const service = require('../../../utils/service.js')
const api = require('../../../utils/util.js')
Page({
  data: {
    myIncomeList: [],
    yzc_status: '0',
    page: 1,
    haveData: true
  },
  init: function() {
    let self = this,
      shop_code = wx.getStorageSync('shopInfo').shop_code,
      shopData = wx.getStorageSync('shop_data');
    api.ajax(service.url('withdrawalList'), {
      unionid: shopData.shop_unionid,
      token: shopData.token,
      token_key: shopData.token_key,
      shop_code: shop_code,
      page: self.data.page,
      yzc_status: self.data.yzc_status
    }, function(res) {
      console.log("已提现already：" + JSON.stringify(res));
      if (res.code == 0) {
        if (Array.isArray(res.data)) {
          self.setData({
            myIncomeList: self.data.myIncomeList.concat(res.data),
            page: self.data.page + 1,
            haveData: res.data.length > 0 ? true : false
          });
        } else {
          api.toast(res.message || '数据出现错误！');
        }
      } else {
        api.toast(res.message || '数据出现错误！');
      }
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (this.data.haveData) {
      this.init();
    } else {
      api.toast("没有更多数据了！");
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      yzc_status: +options.yzc_status
    });
    wx.setNavigationBarTitle({
      title: options.title //页面标题为路由参数
    })
    this.init();
  },
  /**
   * 页面显示/切入前台时触发
   */
  onShow: function() {

  }
})